<!DOCTYPE HTML>
<html lang="en">
<head>
<title>MenuGetHandle() - Syntax &amp; Usage | AutoHotkey</title>
<meta name="description" content="The MenuGetHandle function retrieves the Win32 menu handle of a menu." />
<meta name="ahk:equiv-v2" content="objects/Menu.htm#Handle" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>MenuGetHandle() <span class="ver">[v1.1.23+]</span></h1>

<p>Retrieves the <a href="Menu.htm#Win32_Menus">Win32 menu</a> handle of a menu.</p>
<pre class="Syntax">Handle := <span class="func">MenuGetHandle</span>(MenuName)</pre>

<h2>Parameters</h2>
<dl>

  <dt>MenuName</dt>
  <dd><p>The name of an existing menu. Menu names are not case sensitive.</p></dd>

</dl>

<h2 id="Remarks">Remarks</h2>
<p>The returned handle is valid only until the Win32 menu is destroyed. Once the menu is destroyed, the operating system may reassign the handle value to any menus subsequently created by the script or any other program. Conditions which can cause the menu to be destroyed are listed under <a href="Menu.htm#Win32_Menus">Win32 Menus</a>.</p>

<h2>Related</h2>
<p><a href="Menu.htm">Menu</a>, <a href="MenuGetName.htm">MenuGetName()</a></p>

<h2 id="Examples">Examples</h2>
<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a></p>
<pre>Menu MyMenu, Add, Item 1, no
Menu MyMenu, Add, Item 2, no
Menu MyMenu, Add, Item B, no

<em>; Retrieve the number of items in a menu.</em>
item_count := DllCall("GetMenuItemCount", "ptr", MenuGetHandle("MyMenu"))

<em>; Retrieve the ID of the last item.</em>
last_id := DllCall("GetMenuItemID", "ptr", MenuGetHandle("MyMenu"), "int", item_count-1)

MsgBox, MyMenu has %item_count% items, and its last item has ID %last_id%.

no:
return
</pre>
</div>

</body>
</html>
